<template>
    <section class="WriteOff">
        <div class="service-items">
            <dl>
                <dt><input type="text" v-model="write_off.code" placeholder="请输入卡券号"><button type="button" @click="writeoffStore">核销</button></dt>
                <dd>
                    <ul>
                        <li>
                            <h3>第一步，搜索卡券</h3>
                            <p>请顾客出示卡券，请输入卡券号</p>
                        </li>
                        <li>
                            <h3>第二步，验证卡券信息</h3>
                            <p>验证卡券是否有效</p>
                        </li>
                        <li>
                            <h3>第三步，使用完成</h3>
                            <p>查看使用结果</p>
                        </li>
                    </ul>
                </dd>
            </dl>
        </div>
    </section>
</template>

<script>
    import Request from "@/api/baseRequest.js";
    import { mixin_Coupon } from "@/mixins/coupon.js";
    export default {
        name: "WriteOff",
        props: {},
        mixins: [mixin_Coupon],
        data() {
            return {};
        },
        methods: {
            rules() {
                let { code } = this.write_off;
                if (!code) {
                    this.$Alert({ title: '信息提示', message: '请填写卡券号' });
                    return false;
                }
                return true;
            },
            async writeoffStore() {
                if (!this.rules()) return false;
                this.$set(this.write_off, "storeId", this.GetParam(window.location.href, "storeId") || 0)
                let params = this.write_off;
                const { code, msg } = await Request.verificationCouponCard(params);
                this.$Alert({ title: '信息提示', message: msg });
                if ([200, "200", "OK", 0].includes(code)) {
                    this.write_off.code = '';
                }
            },
        }
    };
</script>

<style lang="less" scoped>
    @import url("@/styles/writeoff.less");
</style>
